#!/usr/bin/env python

# O. Lindemann

# Import modules needed
import pygame
import time




#  Oliver
class LogFile:
    last = 0
    def __init__(self, filename):
        self.last = time.clock()
        self.filename = filename
        self.file = open(self.filename, "w")
        self.file.write("LogFile:")

    def write(self, tag):
        now = time.clock()
        diff = round((now - self.last) * 1000, 0)
        self.last = now
        self.file.write(str(tag) + ": " + str(diff) + "\r")
        return diff
    def __del__(self):
        self.file.close()



def load_image(file_name):
    try:
        image = pygame.image.load(file_name)
    except pygame.error, message:
        print 'Cannot load image:', file_name
        raise SystemExit, message

    return image.convert()




# Settings
screensize = (600, 800)

# Run the main programme if not called as module
if __name__ == "__main__":
    log = LogFile("out.txt")

    pygame.init()
    screen = pygame.display.set_mode((600, 800), pygame.DOUBLEBUF | pygame.HWSURFACE | pygame.FULLSCREEN)
    pygame.mouse.set_visible(False)

    s1 = pygame.Surface(screensize)
    s1.fill((0, 0, 0))
    s2 = pygame.Surface(screensize)
    s2.fill((255, 255, 255))

    start = end = 0
    goOn = True
    s = s2
    while goOn:
        screen.blit(s, (0, 0))
        log.write("blit")
        pygame.display.flip()
        log.write("flip")

        if s == s1:
            s = s2
        else:
            s = s1

        event = pygame.event.poll()
        if event.type == pygame.KEYDOWN and event.key == pygame.K_SPACE:
            goOn = False



